<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :footer="null"
    cancelText="关闭">

    <table id="table_report" class="table table-striped table-bordered table-hover">

      <tr>
        <td style="width:90px;text-align: right;padding-top: 80px;">基本信息:</td>
        <td>
          <p style="float: left;">

            车辆类型名称：<span id="carTypeId" >
              {{ result.carTypeId }}
            </span><br>

            计费规则类型：<span id="ratesType" >
              {{ result.ratesType==='0'?'时间增量计费':'白天黑夜分段计费' }}
            </span><br>

            免费时间状态：<span id="freeTimeStatus" >
              {{ result.freeTimeStatus==='N'?'未启用':'已启用' }}
            </span><br>

            免费时间：<span id="freeTime" >
              {{ result.freeTime+ '分钟' }}
            </span><br>

            创建人：<span id="createUser" >
              {{ result.createUser }}
            </span><br>

            修改时间：<span id="updateTime" >
              {{ result.updateTime }}
            </span><br>

            创建时间：<span id="createTime" >
              {{ result.createTime }}
            </span><br>
          </p>
        </td>
      </tr>

      <tr>
        <td v-if="result.ratesType==='0'" style="width:90px;text-align: right;padding-top: 60px;">详情:</td>
        <td v-if="result.ratesType==='1'" style="width:90px;text-align: right;padding-top: 120px;">详情:</td>
        <td>
          <a-row v-if="result.ratesType==='0'">
            <p>
              首计时单位收费金额（单位分）：<span id="firstMoney" >
                {{ result.firstMoney }}
              </span><br>


              首计时单位（分钟）：<span id="firstUnit" >
                {{ result.firstUnit }}
              </span><br>


              每计时单位收费金额（单位分）：<span id="moneyUnit" >
                {{ result.moneyUnit }}
              </span><br>


              每计时单位（分钟）：<span id="timeUnit" >
                {{ result.timeUnit }}
              </span><br>



              每天最高限额(单位分)：<span id="dayMoneyLimite" >
                {{ result.dayMoneyLimite }}
              </span><br>
            </p>
          </a-row>
          <a-row v-if="result.ratesType==='1'">
            <p>
              白天开始时间：<span id="dayRegionStartHour" >
                {{ result.dayRegionStartHour }}
              </span><br>


              夜间开始时间：<span id="nightRegionStartHour" >
                {{ result.nightRegionStartHour }}
              </span><br>

              白天计时单位：<span id="dayRegionUnitMin" >
                {{ result.dayRegionUnitMin+ '分钟' }}
              </span><br>


              夜晚计时单位：<span id="nightRegionUnitMin" >
                {{ result.nightRegionUnitMin+ '分钟' }}
              </span><br>


              白天每计时单位收费：<span id="dayRegionUnitPrice" >
                {{ result.dayRegionUnitPrice/100 + '元' }}
              </span><br>


              夜间每计时单位收费：<span id="nightRegionUnitPrice" >
                {{ result.nightRegionUnitPrice/100 + '元' }}
              </span><br>


              白天最高收费：<span id="dayRegionMaxPrice" >
                {{ result.dayRegionMaxPrice/100 + '元' }}
              </span><br>


              夜间最高收费：<span id="nightRegionMaxPrice" >
                {{ result.nightRegionMaxPrice/100 + '元' }}
              </span><br>


              白天首计时收费：<span id="dayRegionFirstPrice" >
                {{ result.dayRegionFirstPrice/100 + '元' }}
              </span><br>


              夜间首计时收费：<span id="nightRegionFirstPrice" >
                {{ result.nightRegionFirstPrice/100 + '元' }}
              </span><br>


              白天首计时单位：<span id="dayRegionFirstUnitMin" >
                {{ result.dayRegionFirstUnitMin+ '分钟' }}
              </span><br>


              夜间首计时单位：<span id="nightRegionFirstUnitMin" >
                {{ result.nightRegionFirstUnitMin+ '分钟' }}
              </span><br>
            </p>
          </a-row>
        </td>
      </tr>
      <tr>
        <td style="text-align: center;" colspan="10">
          <a-button type="primary" @click="close">关闭</a-button>
        </td>
      </tr>
    </table>

  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "ConfigParkChargeModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
         result: {

                },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/parking/configParkCharge/add",
          edit: "/parking/configParkCharge/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
             Object.assign(this.result, record);
              this.visible = true;
            },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.updateTime = formData.updateTime?formData.updateTime.format('YYYY-MM-DD HH:mm:ss'):null;

            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>
